<?php
	include_once 'isLogin.php';
	$groupc=new group(); 			//服务类
	$infoc=new info();				//资讯类
	$id=$_GET['id'];				//资讯id
	$smarty->assign('id',$id);
	$table="admin_topic";
	$table_comment="info_comment";	//评论表
	$admin_id=$_COOKIE['admin_id'];


	//修改
	if($id!='' && $id!=null){
		//读取评论
		$where=" ";
		$comment=$infoc->comment_list($id,$where);

		$comment=$comment['result'];
		if(is_array($comment)){
			foreach ($comment as $k => $v) {
				if($v['type']=='user'){
					$comment[$k]['userName']=$v['account'];
				}elseif($v['type']=='admin'){
					$comment[$k]['userName']='小编';
				}
				//判断是否属于回复
				if($v['reply_id']>0){
					if($v['reply_type']=='user'){
						$comment[$k]['replyName']=$v['account1'];
					}elseif($v['reply_type']=='admin'){
						$comment[$k]['replyName']='小编';
					}			
				}
				@$comment[$k]['create_time']=date('Y-m-d H:i:s',$v['create_time']);
			}	
		}
		$smarty->assign('comment',$comment);

		$commentNum=count($comment);
		$smarty->assign('commentNum',$commentNum);

	}

	//删除回复
	if($_GET['action']=='delComment'){
		$tid=$_GET['tid'];				//回复id
		$res=$commonc->del($table_comment,$tid.',');	
	}

	if($_POST['submit']){
		$reply_id=$_POST['reply_id'];
		//读取回复信息
		$info=$commonc->getInfo($table_comment,$reply_id);
 
		$arr= array('info_id'=>$id,
					'comment'=>$_POST['reply_comment'], 
					'type'=>'admin',
					'user_id'=>	$admin_id,
					'create_time'=>time(),
					'reply_id'=>$info['user_id'],
					'reply_type'=>$info['type'],
			);

		$res=$commonc->insert($table_comment,$arr);	

		if($res){
			$msg="操作成功";
		}else{
			$msg="操作失败";
		}

		$href='info_comment.php?id='.$id;
		echo $commonc->submitAlert($msg,$href);
		exit;
	}


	$smarty->display("info_comment.html");
?>